#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101

#include <Macros.h>
#include <CoVector.h>
#include <CoMatrix.h>
#include <CoCube.h>
#include <ValueHelpers.h>
#include <Settings.h>

#pragma unmanaged 
#include <ql\models\marketmodels\models\ctsmmcapletcalibration.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;

using namespace Cephei::QL::Models::Marketmodels;
using namespace Cephei::QL::Math;
#undef HANDLE
#define ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Models { namespace Marketmodels { namespace Models {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of ICTSMMCapletCalibration
	public ref class CCTSMMCapletCalibration : 
            public System::MarshalByRefObject,
            public Cephei::QL::Models::Marketmodels::Models::ICTSMMCapletCalibration
	{
	protected: 
		boost::shared_ptr<QuantLib::CTSMMCapletCalibration>* _ppCTSMMCapletCalibration;
        boost::detail::spinlock* _pSpinlock;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::CTSMMCapletCalibration>* _phCTSMMCapletCalibration;
#endif
		Object^ _CTSMMCapletCalibrationOwner;     // reference to object that manages the storage for this object
	internal:
        CCTSMMCapletCalibration (boost::shared_ptr<QuantLib::CTSMMCapletCalibration>& childNative, Object^ owner);
        CCTSMMCapletCalibration (QuantLib::CTSMMCapletCalibration& childNative, Object^ owner);
        CCTSMMCapletCalibration (CCTSMMCapletCalibration^ copy);
        CCTSMMCapletCalibration (System::Type^ t);
#ifdef STRUCT
        CCTSMMCapletCalibration (QuantLib::CTSMMCapletCalibration childNative);
#endif       
#ifdef HANDLE
		CCTSMMCapletCalibration (QuantLib::Handle<QuantLib::CTSMMCapletCalibration>& childNative, Object^ owner);
		CCTSMMCapletCalibration (QuantLib::Handle<QuantLib::CTSMMCapletCalibration> childNative);
#endif
		virtual ~CCTSMMCapletCalibration ();
		!CCTSMMCapletCalibration ();

	internal:
		QuantLib::CTSMMCapletCalibration& GetReference ();
		boost::shared_ptr<QuantLib::CTSMMCapletCalibration>& GetShared ();
		QuantLib::CTSMMCapletCalibration* GetPointer ();
        void SetCTSMMCapletCalibration (boost::shared_ptr<QuantLib::CTSMMCapletCalibration> native)
        {
            if (_ppCTSMMCapletCalibration != NULL)
                delete _ppCTSMMCapletCalibration;
            _ppCTSMMCapletCalibration = new boost::shared_ptr<QuantLib::CTSMMCapletCalibration> (native);
            
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::CTSMMCapletCalibration>& GetHandle ();
#endif
		virtual bool HasNative () ;
		void Lock ()
		{
			if (Cephei::QL::Settings::_ReferenceLocking)
    			_pSpinlock->lock ();
		}
		void Unlock ()
		{
			_pSpinlock->unlock ();
		}
    public:
		virtual Boolean Calibrate (UInt32 numberOfFactors, UInt32 maxIterations, Double tolerance, Microsoft::FSharp::Core::FSharpOption<UInt32>^ innerMaxIterations, Microsoft::FSharp::Core::FSharpOption<Double>^ innerTolerance) ;
        property Double CapletMaxError 
        {
		    virtual Double get () ;
        }
        property Double CapletRmsError 
        {
		    virtual Double get () ;
        }
        property Cephei::QL::Models::Marketmodels::ICurveState^ CurveState 
        {
		    virtual Cephei::QL::Models::Marketmodels::ICurveState^ get () ;
        }
        property Double DeformationSize 
        {
		    virtual Double get () ;
        }
        property Cephei::IVector<Double>^ Displacements 
        {
		    virtual Cephei::IVector<Double>^ get () ;
        }
        property UInt32 Failures 
        {
		    virtual UInt32 get () ;
        }
        property Cephei::IVector<Double>^ MdlCapletVols 
        {
		    virtual Cephei::IVector<Double>^ get () ;
        }
        property Cephei::IVector<Double>^ MdlSwaptionVols 
        {
		    virtual Cephei::IVector<Double>^ get () ;
        }
        property Cephei::IVector<Double>^ MktCapletVols 
        {
		    virtual Cephei::IVector<Double>^ get () ;
        }
        property Cephei::IVector<Double>^ MktSwaptionVols 
        {
		    virtual Cephei::IVector<Double>^ get () ;
        }
		virtual Cephei::QL::Models::Marketmodels::Models::ICTSMMCapletCalibration^ PerformChecks (Cephei::QL::Models::Marketmodels::IEvolutionDescription^ evolution, Cephei::QL::Models::Marketmodels::IPiecewiseConstantCorrelation^ corr, Cephei::IVector<Cephei::QL::Models::Marketmodels::Models::IPiecewiseConstantVariance^>^ displacedSwapVariances, Cephei::IVector<Double>^ mktCapletVols, Cephei::QL::Models::Marketmodels::ICurveState^ cs) ;
		virtual Cephei::QL::Math::IMatrix^ SwapPseudoRoot (UInt64 i) ;
        property Cephei::IVector<Cephei::QL::Math::IMatrix^>^ SwapPseudoRoots 
        {
		    virtual Cephei::IVector<Cephei::QL::Math::IMatrix^>^ get () ;
        }
        property Double SwaptionMaxError 
        {
		    virtual Double get () ;
        }
        property Double SwaptionRmsError 
        {
		    virtual Double get () ;
        }
		virtual Cephei::IVector<Double>^ TimeDependentCalibratedSwaptionVols (UInt64 i) ;
		virtual Cephei::IVector<Double>^ TimeDependentUnCalibratedSwaptionVols (UInt64 i) ;
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
	public ref class CCTSMMCapletCalibration_Factory : public System::MarshalByRefObject,  public ICTSMMCapletCalibration_Factory
	{
	public:
    };
   
/*Cephei*/ } /*QL*/ } /*Models*/ } /*Marketmodels*/ } /*Models */}
